package com.cc2019.buke.user.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.cc2019.buke.R;
import com.cc2019.buke.user.entry.Address;

import java.util.List;

public class AddressAdapter extends ArrayAdapter<Address> {

    private int resourceId;



    public AddressAdapter(@NonNull Context context, int resource, List<Address> objects) {
        super(context, resource,objects);
        resourceId=resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        Address address=getItem(position);
        View view;
        ViewHolder viewHolder;
        if(convertView==null){
            view= LayoutInflater.from(getContext()).inflate(resourceId,null);
            viewHolder=new ViewHolder();
            viewHolder.address_name=(TextView)view.findViewById(R.id.address_name);
            viewHolder.address_phone=(TextView)view.findViewById(R.id.address_phone);
            viewHolder.address_address=(TextView)view.findViewById(R.id.address_address);
            view.setTag(viewHolder);
        }else {
            view=convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
        viewHolder.address_name.setText(address.getName());
        viewHolder.address_phone.setText(address.getPhone());
        viewHolder.address_address.setText(address.getAddress());
        return view;
    }
}
class ViewHolder{
    TextView address_name;
    TextView address_phone;
    TextView address_address;
}
